<template>
  <el-form ref="postForm" :model="postForm" :rules="rules">
    <sticky :class-name="'sub-navbar'">
      <!--<el-button v-if="!isEdit" @click="showGuide">显示帮助</el-button>-->
      <span style="color:red;font-size:17px">填写完报名信息后点击记得点击→</span>
      <el-button
        v-loading="loading"
        type="success"
        style="margin-left: 10px"
        @click="submitForm"
      >
        {{ isEdit ? '修改并提交' : '保存并提交' }}
      </el-button>
    </sticky>
    <div class="detail-container">
      <el-row>
        <warning />
        <el-col :span="24">
          <el-row>
            <el-col :span="12">
              <el-form-item prop="post" label="报考岗位：" :label-width="labelWidth">
                <el-select v-model="postForm.post" disabled placeholder="请选择" clearable>
                   <el-option
                      v-for="item in post_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item> 
            </el-col>
            <el-col :span="12">
              <el-form-item prop="post_code" label="岗位代码：" :label-width="labelWidth" >
                <el-select v-model="postForm.post_code" disabled placeholder="请选择" clearable>
                   <el-option
                      v-for="item in post_code_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="enroll_name" label="姓名：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.enroll_name"
                  placeholder="姓名"
                />
              </el-form-item>
            </el-col>
            
            <el-col :span="12">
              <el-form-item prop="sex" label="性别："  :label-width="labelWidth" >
                <el-radio-group v-model="postForm.sex">
                  <el-radio label="男"></el-radio>
                  <el-radio label="女"></el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
           
          </el-row>
          
          <el-row>
            <el-col :span="12">
              <el-form-item prop="politics_status" label="政治面貌：" :label-width="labelWidth" >
                <el-select v-model="postForm.politics_status" placeholder="请选择" clearable>
                  <el-option
                      v-for="item in politics_status_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="ethnic" label="民族：" :label-width="labelWidth">
                <el-select v-model="postForm.ethnic" placeholder="请选择" clearable>
                   <el-option
                      v-for="item in ethnic_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="education_background" label="最高学历：" :label-width="labelWidth" >
                <el-select v-model="postForm.education_background" placeholder="请选择" clearable>
                  <el-option
                      v-for="item in education_background_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="degree" label="最高学位：" :label-width="labelWidth" >
                <el-select v-model="postForm.degree" placeholder="请选择" clearable>
                  <el-option
                      v-for="item in degree_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
        
              <el-col :span="12">
              <el-form-item prop="zhichengjibie" label="专业技术职称级别：" :label-width="labelWidth" >
                <el-select v-model="postForm.zhichengjibie" @change="handleChangezhicheng" placeholder="请选择">
                  <el-option
                      v-for="item in zhicheng_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                      >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            
            <el-col :span="12">
              <el-form-item prop="date_of_birth" label="出生年月：" :label-width="labelWidth" >
                <el-date-picker
                  v-model="postForm.date_of_birth"
                  type="date"
                  placeholder="出生年月"
                  value-format="yyyy.MM.dd">
                </el-date-picker>
              </el-form-item>
            </el-col>
           
          </el-row>
          <el-row v-if="showzhicheng==true">
            <el-col :span="12">
            <el-form-item prop="zhicheng" label="专业技术职称：" :label-width="labelWidth" >
              <el-input
                v-model="postForm.zhicheng"
                placeholder="专业技术职称"
              />
            </el-form-item>
            </el-col>
            
         
        </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="school_and_date_of_graduation" label="毕业学校：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.school_and_date_of_graduation"
                  placeholder="毕业学校"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="graduation_time" label="毕业时间：" :label-width="labelWidth" >
                <el-date-picker
                  v-model="postForm.graduation_time"
                  type="date"
                  placeholder="毕业证毕业时间"
                  value-format="yyyy.MM.dd">
                </el-date-picker>(应届毕业生填写预毕业时间)
              </el-form-item>
            </el-col>
          </el-row>   
          <el-row>
            <el-col :span="12">
              <el-form-item prop="what_specific" label="专业名称：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.what_specific"
                  placeholder="专业名称"
                />
                </el-form-item>
            </el-col>
            <el-col :span="12" v-if="showfangxiang==true">
              <el-form-item prop="main_specialties" label="专业方向：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.main_specialties"
                  placeholder="专业方向"
                />
              </el-form-item>
            </el-col>
          </el-row> 
          <el-row>
            <el-col :span="12">
              <el-form-item prop="ID_card_No" label="身份证号码：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.ID_card_No"
                  placeholder="身份证号码"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="contact_way" label="联系电话：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.contact_way"
                  placeholder="联系方式"
                />
              </el-form-item>
            </el-col>
          </el-row> 
          
          
        
          <!--<el-row>
            <el-col :span="24">
              <el-form-item prop="photo" label="本人照片：" :label-width="labelWidth">
                <el-upload
                  class="upload-demo"
                  ref="upload"
                  action="https://test.resume1234.top:18082/enroll/uploadEnroll"
                  name="file"
                  :data="userInfo"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :file-list="fileList"
                  list-type="picture"
                  :auto-upload="false"
                  :on-success="onsuccess"
                  :before-upload="beforeAvatarUpload"
                >
                  <el-button slot="trigger" size="small" type="primary">点击上传</el-button>
                  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
                  <div slot="tip" class="el-upload__tip">只能上传jpg图片，且不超过2MB</div>
                </el-upload>
              </el-form-item>
            </el-col> 
          </el-row> 
          -->
          <el-row>
            <el-col :span="24">
              <el-form-item prop="resume" label="现工作单位：" :label-width="labelWidth" >
                <el-input
                  v-model="postForm.resume"
                  placeholder="应届毕业生、无、有工作单位人员按实际填写"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="achievement" label="现在研究方向及主要成果：" :label-width="labelWidth">
                <el-input
                  type="textarea"
                  :rows="6"
                  placeholder="请输入内容"
                  v-model="postForm.achievement">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          
          <el-row>
            <el-col :span="24">
              <el-form-item prop="enroll_img" label="上传证明材料：" :label-width="labelWidth">
                <el-upload
                  prop="enroll_img"
                  class="upload-demo"
                  ref="upload"
                  action="https://dhszzp.top:18082/enroll/uploadEnroll"
                  name="file"
                  :data="userInfo"
                  accept=".jpg,.jpeg,.JPG,.JPEG"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :file-list="fileList"
                  list-type="picture"
                  :auto-upload="false"
                  :on-success="onsuccess"
                  :before-upload="beforeAvatarUpload"
                  multiple
                >
                  <el-button slot="trigger" size="small" type="primary">1.选择文件</el-button>
                  <el-button style="margin-left: 10px;" size="small" type="success" @click=" submitUpload">2.点击上传</el-button>
                  <div slot="tip" class="el-upload__tip" style="color:red;font-size:16px;line-height:16px">步骤：1.选择文件；2.选择好文件后点击上传。注意：只能上传jpg、jpeg图片，且不超过1MB。
                    <p style="color:black;font-size:15px;line-height:25px"><b>提交材料:</b>1.本人有效居民身份证扫描件；<br>2.毕业证、学位证扫描件。其中，暂未取得毕业证、学位证的2023年应届毕业生须提供《普通高等院校毕业生就业推荐表》；<br>3.国（境）外毕业生还须提供经教育部留学服务中心认证的《教育部国（境）外学历学位认证书》。《教育部国（境）外学历学位认证书》应载明专业或专业领域或专业方向。学历学位由教育部留学服务中心认证，报考人员可登录教育部留学服务中心网站（http://www.cscse.edu.cn）查询认证的有关要求和程序；<br>4.证明本人工作技能的职称（职业资格）证书或专业等级考核证书扫描件；<br>5.202301001、202301002、202301003、202301004、202301005、202301006、202301007和202301012等有专业方向要求的岗位，毕业证学位证上未注明专业方向的，须提供加盖学校或研究生院出具的专业方向证明。无法提供证明或相提供的证明不符合要求的，均按资格审查不通过办理；<br>6.202301002和202301004岗位需要提供本科及研究生阶段学历学位证书；<br>7.报考岗位所要求的其他支撑材料原件扫描件。
                    </p>
                  </div>
                </el-upload>
              </el-form-item>
            </el-col> 
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="zpyq" label="招聘公告相关规定："  :label-width="labelWidth" >
                <el-switch v-model="postForm.zpyq"></el-switch>&nbsp&nbsp<b>不存在</b>&nbsp&nbsp(是否存在公告规定的不得报考或不能报考情形之一）
              
              </el-form-item>
              
            </el-col>
          </el-row>
          
          
          
        </el-col>
      </el-row>
    </div>
  </el-form>
</template>

<script>
// eslint-disable-next-line
/* eslint-disable */
import Cookies from 'js-cookie'

import Sticky from '../../../components/Sticky'
import { validateSfz } from "@/utils/validate.js";
import Warning from './Warning'
import { createEnroll, updateEnroll, getOneEnroll ,listEnroll, createEnrollExamine } from '../../../api/enroll'
//import MarkdownEditor from '@/components/MarkdownEditor'
const fields = {
  
}
export default {
  
  components: { Sticky, Warning },
  props: {
    isEdit: Boolean
  },
  data() {
    const validateRequire = (rule, value, callback) => {
      if (value.length === 0) {
        callback(new Error(fields[rule.field] + '必须填写'))
      } else {
        callback()
      }
    }
    const zpyqval = (rule, value, callback) => {
      if (value!= true) {
        callback(new Error("请认真阅读招聘公告相关规定并选择已阅读"))
      } else {
        callback()
      }
    }
    
    const validateContactNumber = (rule, value, callback) => {
  const reg = /^[1][1,2,3,4,5,7,8,9][0-9]{9}$/;
  if (value == '' || value == undefined || value == null) {
    callback(new Error('请输入电话号码'));
  } else {
    if ((!reg.test(value)) && value != '') {
      callback(new Error('请输入正确的电话号码'))
    } else {
      callback()
    }
  }
    }
    //判断出生日期，必须小于35周岁
    const validateDate = (rule, value, callback) => {

    if (value == ''|| value == undefined || value == null) {
      callback(new Error('请输入出生日期'))
      
    } else if(value != ''){
      //var date="1987.03.01";
		  var birthdays = new Date(value.replace(/-/g, "/"));
      var d = new Date("2023-03-30");//判断出生日期基数
      var age = d.getFullYear() -birthdays.getFullYear() -(d.getMonth() < birthdays.getMonth() || (d.getMonth()== birthdays.getMonth() && d.getDate() < birthdays.getDate()) ? 1 : 0);
      console.log(age);
      console.log(this.postForm.zhicheng);
      console.log(this.postForm.education_background);
      
      if(age>=35){
        if(this.postForm.zhichengjibie=="中级"||this.postForm.zhichengjibie=="副高级"||this.postForm.zhichengjibie=="正高级" || this.postForm.education_background=="博士研究生"){
          callback()
        }else{
          callback(new Error('年龄超过35周岁'))
        }
        
      }else if(age<=18){
        callback(new Error('年龄小于18周岁'))
      }else{
        callback()
      }
    }else{
        callback()
      }
    }
    return {
      loading: false,
      postForm: {date_of_birth:'',graduation_time:'',zpyq:false,
      enroll_status:"已提交",enroll_adminuser:'',
      enroll_img:[],achievement:'',resume:'',
      politics_status_time:"无",ljsbz:'无',ljs:'无',fx:'无',Current_Registered_Household:'无'},
      fileList: [],
      postForm_examine: {examine_status:'已提交', examine_name:'',examine_operator:'',examine_time:'',examine_explain:''},
      fileList_enroll:[],
      listQuery: {},
      arr1:[],
      userInfo: {},
      labelWidth: '120px',
      categoryList:[],
      date_of_birth:'',
      baoming:'',
      listbaoming:[],
      showfangxiang:false,
      showzhicheng:false,
      rules: {
        enroll_name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        post: [{required: true, message: '请输入报考岗位', trigger: 'blur'}],
        post_code: [{ required: true, message: '请选择岗位代码', trigger: 'change' }],
        date_of_birth: [{ required: true, trigger: 'change' ,validator: validateDate }],
        sex: [{ required: true, message: '请选择性别', trigger: 'blur' }],
        ethnic: [{ required: true, message: '请选择民族', trigger: 'change' }],
        politics_status: [{required: true, message: '请选择政治面貌', trigger: 'change'}],
        //politics_status_time: [{required: true, message: '请选择加入时间', trigger: 'blur'}],
        education_background: [{ required: true, message: '请选择最高学历', trigger: 'change' }],
        degree: [{ required: true, message: '请选择最高学位', trigger: 'change' }],
        school_and_date_of_graduation: [{ required: true, message: '请输入毕业学校', trigger: 'blur' }],
        graduation_time: [{ required: true, message: '请输入毕业时间', trigger: 'blur' }],
        what_specific: [{required: true, message: '请输入所学专业：', trigger: 'blur'}],
        //main_specialties: [{ required: true, message: '请输入专业方向', trigger: 'blur' }],
        degree: [{ required: true, message: '请输入学位', trigger: 'blur' }],
        //Current_Registered_Household: [{ required: true, message: '请输入现居住地（省市县村，精确到村或街道 ）如：云南省德宏州芒市勐焕街道芒市花园', trigger: 'blur' }],
        ID_card_No: [{required: true, trigger: 'blur',validator:validateSfz}],
        contact_way: [{ required: true, trigger: 'blur',validator: validateContactNumber }],
        main_specialties: [{ required: true, message: '请输入专业方向', trigger: 'blur' }],
        achievement: [{ required: true, message: '请输入现在研究方向及主要成果', trigger: 'blur' }],
        resume: [{ required: true, message: '请输入现工作单位', trigger: 'blur' }],
        enroll_img: [{ required: true, message: '请提交上传的证明材料：', trigger: 'blur' }],
        //fx: [{ required: true, message: '请选择现居住地是否中高风险地区', trigger: 'blur' }],
        //ljs: [{ required: true, message: '请选择14天内是否国内中高风险或近1个月内境外旅居史', trigger: 'blur' }],
        zhichengjibie: [{ required: true, message: '请选择专业技术职称级别', trigger: 'change' }],
        zhicheng: [{ required: true, message: '请填写专业技术职称', trigger: 'blur' }],
        zpyq: [{ required: true, trigger: 'blur',validator:zpyqval}],
        //ljsbz: [{ required: true, message: '请输入如有：14天内是否国内中高风险或近1个月内境外旅居史进行详细说明', trigger: 'blur' }],
      },
      post_options: [{
          value: '德宏师专教学岗',
          label: '德宏师专教学岗'
        }, {
          value: '德宏师专管理岗',
          label: '德宏师专管理岗'
        }],
      zhicheng_options: [{
        value: '无',
        label: '无'
      }, {
        value: '初级',
        label: '初级'
      },{
        value: '中级',
        label: '中级'
      },{
        value: '副高级',
        label: '副高级'
      },{
        value: '正高级',
        label: '正高级'
      }],
      
      post_code_options:[{
          value: '2021bw001',
          label: '2021bw001'
        }, {
          value: '2021bw002',
          label: '2021bw002'
        },{
          value: '2021bw003',
          label: '2021bw003'
        }, {
          value: '2021bw004',
          label: '2021bw004'
        }, {
          value: '2021bw005',
          label: '2021bw005'
        }, {
          value: '2021bw006',
          label: '2021bw006'
        }, {
          value: '2021bw007',
          label: '2021bw007'
        }, {
          value: '2021bw008',
          label: '2021bw008'
        }, {
          value: '2021bw009',
          label: '2021bw009'
        }, {
          value: '2021bw010',
          label: '2021bw010'
        }, {
          value: '2021bw011',
          label: '2021bw011'
        }, {
          value: '2021bw012',
          label: '2021bw012'
        }, {
          value: '2021bw013',
          label: '2021bw013'
        }, {
          value: '2021bw014',
          label: '2021bw014'
        }, {
          value: '2021bw015',
          label: '2021bw015'
        }],
      politics_status_options:[
        {
          value: "中共党员",
          label: "中共党员"
        },{
          value: "中共预备党员",
          label: "中共预备党员"
        },{
          value: "共青团员",
          label: "共青团员"
        },{
          value: "民革党员",
          label: "民革党员"
        },{
          value: "民盟盟员",
          label: "民盟盟员"
        },{
          value: "民建会员",
          label: "民建会员"
        },{
          value: "民进会员",
          label: "民进会员"
        },{
          value: "农工党党员",
          label: "农工党党员"
        },{
          value: "致公党党员",
          label: "致公党党员"
        },{
          value: "九三学社社员",
          label: "九三学社社员"
        },{
          value: "台盟盟员",
          label: "台盟盟员"
        },{
          value: "群众",
          label: "群众"
        },{
          value: "无党派",
          label: "无党派"
        },
        
      ],
      education_background_options:[
        {
          value: "硕士研究生",
          label: "硕士研究生"
        },{
          value: "博士研究生",
          label: "博士研究生"
        }
      ],
      degree_options:[
        {
          value: "硕士",
          label: "硕士"
        },{
          value: "博士",
          label: "博士"
        }
      ],
      ethnic_options: [
        {value:"汉族",label:"汉族"},{value:"蒙古族",label:"蒙古族"},{value:"回族",label:"回族"},
        {value:"藏族",label:"藏族"},{value:"维吾尔族",label:"维吾尔族"},{value:"苗族",label:"苗族"},
        {value:"彝族",label:"彝族"},{value:"壮族",label:"壮族"},{value:"布依族",label:"布依族"},
        {value:"朝鲜族",label:"朝鲜族"},{value:"满族",label:"满族"},{value:"侗族",label:"侗族"},
        {value:"瑶族",label:"瑶族"},{value:"白族",label:"白族"},{value:"土家族",label:"土家族"},
        {value:"哈尼族",label:"哈尼族"},{value:"哈萨克族",label:"哈萨克族"},{value:"傣族",label:"傣族"},
        {value:"黎族",label:"黎族"},{value:"傈僳族",label:"傈僳族"},{value:"佤族",label:"佤族"},
        {value:"畲族",label:"畲族"},{value:"高山族",label:"高山族"},{value:"拉祜族",label:"拉祜族"},
        {value:"水族",label:"水族"},{value:"东乡族",label:"东乡族"},{value:"纳西族",label:"纳西族"},
        {value:"景颇族",label:"景颇族"},{value:"柯尔克孜族",label:"柯尔克孜族"},{value:"土族",label:"土族"},
        {value:"达斡尔族",label:"达斡尔族"},{value:"仫佬族",label:"仫佬族"},{value:"羌族",label:"羌族"},
        {value:"布朗族",label:"布朗族"},{value:"撒拉族",label:"撒拉族"},{value:"毛难族",label:"毛难族"},
        {value:"仡佬族",label:"仡佬族"},{value:"锡伯族",label:"锡伯族"},{value:"阿昌族",label:"阿昌族"},
        {value:"普米族",label:"普米族"},{value:"塔吉克族",label:"塔吉克族"},{value:"怒族",label:"怒族"},
        {value:"乌孜别克族",label:"乌孜别克族"},{value:"俄罗斯族",label:"俄罗斯族"},{value:"鄂温克族",label:"鄂温克族"},
        {value:"崩龙族",label:"崩龙族"},{value:"保安族",label:"保安族"},{value:"裕固族",label:"裕固族"},
        {value:"京族",label:"京族"},{value:"塔塔尔族",label:"塔塔尔族"},{value:"独龙族",label:"独龙族"},
        {value:"鄂伦春族",label:"鄂伦春族"},{value:"赫哲族",label:"赫哲族"},{value:"门巴族",label:"门巴族"},
        {value:"珞巴族",label:"珞巴族"},{value:"基诺族",label:"基诺族"}
      ],
    }
  },
 
  created() {
    //获取用户信息
   
    let usernameinfo=Cookies.get('username')
    
    this.userInfo={"username":usernameinfo}
    
      
        if (this.isEdit) {
      const fileName = this.$route.params.fileName
      getOneEnroll(fileName).then(response => {
        //console.log(response)
        this.postForm=response.data
        this.postForm.zpyq=(response.data.zpyq='true')?true:false
        if(this.postForm.politics_status_time==="null"){
          this.postForm.politics_status_time=""
        }
        this.arr1 = JSON.parse(response.data.enroll_img)
        //console.log(this.arr1)
        this.arr1.forEach((item)=>{
          //console.log(item.name)
            this.fileList.push({name: item.name, url: item.url})
            this.fileList_enroll.push({name: item.name, url: item.url})
            console.log(this.fileList)
        })

      }
   ).catch(() => {
        this.loading = false
      })
      //console.log(fileName)
    }else{
      //判断是否是admin用户
      let fileName1 = this.$route.params.fileName
      let fileName11=fileName1.split("&")
      this.postForm.post=fileName11[1]
      this.postForm.post_code=fileName11[0]
      if(fileName11[2]!="无"){
        this.showfangxiang=true
      }
      //const fileName12=fileName1.toJSONString()
      //console.log(fileName11[0])
      if(usernameinfo!='admin'){
          this.listQuery.enroll_adminuser=usernameinfo
          listEnroll(this.listQuery).then(response => {
          if(response.data.count>0){
            this.$notify({
            title: '你已经填写过了报名信息，不能重复报名',
            message: '报名失败',
            type: 'error',
            duration: 2000
          }) 
          this.$router.push('/enroll/list')
          }

        })
      }
    }

  },
  methods: {
    // 获取服务器时间的异步函数
    getServerDate(){
      var xhr = null;
      if(window.XMLHttpRequest){
      xhr = new window.XMLHttpRequest();
      }else{ // ie
      xhr = new ActiveObject("Microsoft")
      }
      xhr.open("GET","/",true);
      xhr.send(null);
      xhr.onreadystatechange=function(){
      var time,date;
      if(xhr.readyState == 2){
      time = xhr.getResponseHeader("Date");
      date = new Date(time);
      console.log(date);
      }
    }
    },
    handleChangezhicheng(){
      console.log(this.postForm.zhichengjibie)
      if(this.postForm.zhichengjibie!="无"){
        this.showzhicheng=true
      }
      else{
        this.showzhicheng=false
        this.postForm.zhicheng="无"
      }
      console.log(this.postForm.zhicheng)
    },
    onContentClick(data) {
      ////console.log(data)
      if (data.text) {
        window.open(data.text)
      }
    },
    setDefault() {
      // this.postForm = Object.assign({}, defaultForm)
      this.$router.push({
        path: '/',
      })
      //this.postForm={state:"1"}
    },
    
    onsuccess(res){
       this.$notify({
          title: '上传资料图片成功',
          message: '上传资料图片成功',
          type: 'success',
          duration: 2000
        }) 
     
      this.fileList_enroll.push({name: res.data.originalName, url: res.data.url})
      
      
    },
    beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 1;

        if (!isJPG) {
          this.$message.error('上传图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传图片大小不能超过 1MB!');
        }
        return isJPG && isLt2M;
    },
    submitUploadEnroll(){
        this.$refs.upload.submit();
    },
    submitUpload(){
        this.$refs.upload.submit();
    },
    handlePreview(file){
      //console.log("preview"+file)
    },
    

    handleRemove(file, fileList) {
      
      this.fileList_enroll=[]
      fileList.forEach((item)=>{
          ////console.log(item.uid)
            this.fileList_enroll.push({name: item.name, url: item.url})
        })
      
    },
    getCategoryList() {
      
    },
    submitForm() {
      
      
        const onSuccess = (response) => {
        const { msg } = response
        this.$notify({
          title: '操作成功',
          message: msg,
          type: 'success',
          duration: 2000
        })
        this.loading = false
      }

      if (!this.loading) {
        this.loading = true
        this.postForm.enroll_status="已提交"
      
        this.postForm.enroll_img=JSON.stringify(this.fileList_enroll)
        //console.log("11"+this.postForm.enroll_img)
        this.$refs.postForm.validate((valid, fields) => {
          //console.log(valid, fields)
          if (valid) {
            let usernameinfo=Cookies.get('username')
            this.postForm.enroll_adminuser=usernameinfo
            const enroll = Object.assign({}, this.postForm)
            console.log(enroll)
            this.postForm_examine.examine_name=usernameinfo
            this.postForm_examine.examine_operator=usernameinfo
            ////console.log(this.postForm_examine.politics_status_time)
            const enroll_examine=Object.assign({}, this.postForm_examine)
            if (!this.isEdit) {
                  enroll_examine.examine_explain="报名表保存并提交，等待初审"
                  createEnroll(enroll).then(response => {
                  onSuccess(response)
                  createEnrollExamine(enroll_examine).then(responsel => {
                      onSuccess(responsel)
                      this.setDefault()
                    }).catch(() => {
                      this.loading = false
                    })
                }).catch(() => {
                  this.loading = false
                })
            } else {
              updateEnroll(enroll).then(response => {
                enroll_examine.examine_explain="报名表修改保存并提交，等待初审"
                onSuccess(response)
                createEnrollExamine(enroll_examine).then(responsel => {
                      onSuccess(responsel)
                      this.setDefault()
                    }).catch(() => {
                      this.loading = false
                    })
              }).catch(() => {
                this.loading = false
              })
            }
          } else {
            const message = fields[Object.keys(fields)[0]][0].message
            this.$message({ message, type: 'error' })
            this.loading = false
          }
        })
      }
    
  },
    showGuide() {
      //console.log('show guide...')
    }
  
  }
}
</script>

<style lang="scss" scoped>
  .detail-container {
    padding: 40px 50px 20px;
    .preview-img {
      width: 200px;
      height: 270px;
    }
  }
</style>
